﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using System.IO;
using ScrumTable.Common;
using ScrumTable.Common.Test;
using ScrumTable.DL.Data.Common;
using ScrumTable.DL.Data.Common.Config.Driver;
using ScrumTable.DL.Data.Common.Config.Schema;

#endregion

namespace ScrumTable.DL.Data.Generic.Test.Mocks
{
    /// <summary>
    /// This is a fake implementaion for the IDataContextInfo class.
    /// </summary>
    public class DataContextInfoStub : IDataContextInfo
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets the selected source for the schema configuration.
        /// </summary>
        public IDataSchemaSource ConfiguredSchemaSource { get; private set; }

        /// <summary>
        /// Gets the selected source for the driver configuration.
        /// </summary>
        public IDriverConfigSource ConfiguredDriverConfigSource { get; private set; }

        /// <summary>
        /// Gets the description of the data assembly. This property may be
        /// used in a UI drop down list in order to select a proprietary
        /// data connector plug in.
        /// </summary>
        string IDataAssemblyInfo.Description { get { return "Provides A Stub For Test Purposes"; } }

        /// <summary>
        /// Returns true if the data assembly reqiures strong username / password authentication.
        /// </summary>
        bool IDataAssemblyInfo.AssemblyRequiresStrongAuthentication { get { return false; } }

        /// <summary>
        /// Specifies the data assembly format for the driver data source link (passed to the Connect()).
        /// </summary>
        DataSourceLinkFormat IDataAssemblyInfo.AssemblyRequiredLinkFormat { get { return DataSourceLinkFormat.None; } }

        /// <summary>
        /// Gets the schema data sources associated to the current data assembly and
        /// its data driver.
        /// </summary>
        public IDataSchemaSelector DataSchemaSelector { get; private set; }

        /// <summary>
        /// Gets the configuration data sources associated to the current data assembly and
        /// its data driver.
        /// </summary>
        public IDriverConfigSelector DriverConfigSelector { get; private set; }

        /// <summary>
        /// Gets the user specific configuration folder path for the current application.
        /// </summary>
        public string ConfigFolderPath { get; private set; }

        /// <summary>
        /// Gets the user specific data folder path for the current application.
        /// </summary>
        public string DataFolderPath { get; private set; }

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new DataContextInfoStub instance.
        /// </summary>
        public DataContextInfoStub(
            string testDir,
            Func<IDataContextInfo, IDataSchemaSelector> toGetSchemaSelector,
            Func<IDataContextInfo, IDriverConfigSelector> toGetDriverConfigSelector)
        {
            PreCondition.AssertNotNullOrEmpty(testDir, "testDir");
            PreCondition.AssertNotNull(toGetSchemaSelector, "toGetSchemaSelector");
            PreCondition.AssertNotNull(toGetDriverConfigSelector, "toGetDriverConfigSelector");

            ConfigFolderPath = testDir;
            DataFolderPath = testDir;
            
            DataSchemaSelector = toGetSchemaSelector(this);
            DriverConfigSelector = toGetDriverConfigSelector(this);

            ConfiguredSchemaSource = DataSchemaSelector.Selected;
            ConfiguredDriverConfigSource = DriverConfigSelector.Selected;
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Maps a file path to a file which is stored on the underlying 
        /// hard drive in conjunction with the data file-system data retrieval rules.
        /// </summary>
        /// <param name="fileToMap">Specifies the file path which should be mapped through the plugin system.</param>
        /// <returns>Returns a mapped file path which points the a file on the file system.</returns>
        public string MapDataFilePath(string fileToMap)
        {
            if (Path.IsPathRooted(fileToMap))
            {
                return fileToMap;
            }
            return ResourceUtil.CombineToProjectPath(DataFolderPath, fileToMap);
        }

        /// <summary>
        /// Maps a folder path to a file which is stored on the underlying 
        /// hard drive in conjunction with the data driver file-system data retrieval rules.
        /// </summary>
        /// <param name="folderToMap">Specifies the file path which should be mapped through the plugin system.</param>
        /// <returns>Returns a mapped file path which points the a file on the file system.</returns>
        public string MapDataFolderPath(string folderToMap)
        {
            if (Path.IsPathRooted(folderToMap))
            {
                return folderToMap;
            }
            return ResourceUtil.CombineToProjectPath(DataFolderPath, folderToMap);
        }

        /// <summary>
        /// Maps a file path to a file which is stored on the underlying 
        /// hard drive in conjunction with the config file-system data retrieval rules.
        /// </summary>
        /// <param name="fileToMap">Specifies the file path which should be mapped through the plugin system.</param>
        /// <returns>Returns a mapped file path which points the a file on the file system.</returns>
        public string MapConfigFilePath(string fileToMap)
        {
            if (Path.IsPathRooted(fileToMap))
            {
                return fileToMap;
            }
            return ResourceUtil.CombineToProjectPath(ConfigFolderPath, fileToMap);
        }

        /// <summary>
        /// Maps a folder path to a file which is stored on the underlying 
        /// hard drive in conjunction with the config driver file-system data retrieval rules.
        /// </summary>
        /// <param name="folderToMap">Specifies the file path which should be mapped through the plugin system.</param>
        /// <returns>Returns a mapped file path which points the a file on the file system.</returns>
        public string MapConfigFolderPath(string folderToMap)
        {
            if (Path.IsPathRooted(folderToMap))
            {
                return folderToMap;
            }
            return ResourceUtil.CombineToProjectPath(ConfigFolderPath, folderToMap);
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}
